#!/usr/bin/env python

import sys, re

def convert( stream, auto_naming=False ):

	output = []
	
	for ln in stream:
		lhs, rhs = [], []
		sw       = False
		ln       = re.split( "[ \]&|]", ln.strip() )
		

		if "->" not in ln: i, clause, nm_constraints = ln[0], ln[1:-2], ln[-2]
		else:              i, clause                 = ln[0], ln[1:-1]

		for c in clause:
			if "" == c: continue
			if "->" == c:
				sw = True
				continue

			c                = re.split( "[:(,)]", c )

			if "{}" == c[-1]: literal, j, cost = c[0:-5], c[-4], c[-3]
			else:             literal, cost    = c[0:-2], "%.2f" % (float(c[-1]) / 100.0)
			
			if not sw: lhs += ["%s(%s):%s" % ( literal[0], ", ".join( literal[1:] ), cost )]
			else:      rhs += ["%s(%s)"    % ( literal[0], ", ".join( literal[1:] ) )]

		if "->" not in ln:
			for nm in nm_constraints.split( "," ):
				if "" == nm.strip(): continue
				nm   = nm.split( "-" )
				lhs += ["%s != %s" % (nm[0], nm[1])]
			
		if auto_naming:
			if not sw: output += ["%s] %s" % ( i, " & ".join( lhs ) )]
			else:      output += ["%s] %s => %s" % ( i, " & ".join( lhs ), " & ".join( rhs ) )]
		else:
			if not sw: output += [" & ".join( lhs )]
			else:      output += ["%s => %s" % ( " & ".join( lhs ), " & ".join( rhs ) )]
			
	return "\n".join( output )


def main():
	print convert( sys.stdin, True )
	
if "__main__" == __name__: main()
